package com.gitee.linzl.zuul.gateway.config;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Profile;
import org.springframework.web.context.request.async.DeferredResult;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurationSupport;

import springfox.documentation.builders.ApiInfoBuilder;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.service.Contact;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2;

@Configuration
@Profile({ "dev" })
@EnableSwagger2
public class SwaggerConfig extends WebMvcConfigurationSupport {
	private Contact contact = new Contact("linzl", "https://gitee.com/_linzl/", "2225010489@qq.com");

	@Bean
	public Docket allApi() {
		ApiInfo apiInfo = new ApiInfoBuilder().title("API列表")// 大标题
				.description("API网关")// 详细描述
				.version("1.0")// 版本
				.termsOfServiceUrl("NO terms of service").contact(contact)// 作者
				.build();
		return new Docket(DocumentationType.SWAGGER_2)

				.genericModelSubstitutes(DeferredResult.class)
				// .genericModelSubstitutes(ResponseEntity.class)
				.useDefaultResponseMessages(false)

				.forCodeGeneration(false).pathMapping("/").select()
				// .paths(or(regex("/tbDevicegroup.*"),regex("/tb*.*")))//过滤的接口
				.build().apiInfo(apiInfo);
	}

	@Override
	public void addResourceHandlers(ResourceHandlerRegistry registry) {
		registry.addResourceHandler("swagger-ui.html").addResourceLocations("classpath:/META-INF/resources/");
		registry.addResourceHandler("/webjars*").addResourceLocations("classpath:/META-INF/resources/webjars/");
	}
	// @Bean
	// public Docket createRestApi() {
	// ParameterBuilder tokenBuilder = new ParameterBuilder();
	// tokenBuilder.name("Authorization")
	// .defaultValue("去其他请求中获取heard中token参数")
	// .description("令牌")
	// .modelRef(new ModelRef("string"))
	// .parameterType("header")
	// .required(true).build();
	//
	// List<Parameter> parameterList = new ArrayList<Parameter>();
	// parameterList.add(tokenBuilder.build());
	//
	// return new Docket(DocumentationType.SWAGGER_2).groupName("all")
	// .apiInfo(apiInfo()).select()
	// //.apis(RequestHandlerSelectors.withMethodAnnotation(ApiOperation.class))
	// .paths(PathSelectors.any())
	// .build();// .globalOperationParameters(parameterList);"/"
	// }
	// }
}